package samsung.sds.groupManagement.service.impl;

import java.math.BigDecimal;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import samsung.sds.groupManagement.dao.GroupUserMapper;
import samsung.sds.groupManagement.model.GroupUserEntity;
import samsung.sds.groupManagement.service.GroupUserManagementService;
import samsung.sds.system.common.baseQuery.AbstractBaseService;
import samsung.sds.system.common.baseQuery.BaseMapper;
import samsung.sds.system.common.baseQuery.model.PageData;
import samsung.sds.system.common.model.QueryParam;
import samsung.sds.system.utils.CommonTools;
import samsung.sds.userManagement.model.UserEntity;
/**
 * @author lulu.yuan
 * @craeteDate 2016-02-19
 * 
 * groupUserManagement的service组件
 */
@Service
public class GroupUserManagementServiceImpl extends AbstractBaseService<GroupUserEntity> implements GroupUserManagementService{

	@Autowired
	private GroupUserMapper groupUserMapper;
	
	/**
	 * 获取groupUserMapper
	 */
	@Override
	protected BaseMapper<GroupUserEntity> getMapper() {
		return groupUserMapper;
	}
	
    /**
	 * 给组添加用户
	 * @param groupUserEntity
	 */
    public void InsertUsesToGroup(String[] userNamesArr,String groupId){    
		for (String userName : userNamesArr) {	
			GroupUserEntity groupUserEntity = new GroupUserEntity();
			groupUserEntity.setGroupId(groupId);
			groupUserEntity.setUserName(userName);				
			groupUserEntity.setCreateUser(CommonTools.getSessionUserName());				
			groupUserMapper.insertTF_F_GROUP_USER( groupUserEntity ); 
		}		 
    }
	
	/**
	 * 从组中删除用户
	 * @param userNames
	 * @param groupId
	 */
	public int deleteUsersFromGroup(List<String> userNames, String groupId){
		return groupUserMapper.deleteTF_F_GROUP_USER02( userNames, groupId );
	}
	
	/**
	 * 查询用户分页列表（方法重写）
	 * @param param
	 * @return
	 */
	public PageData<UserEntity> queryUsersListPage(QueryParam param) {
		List<UserEntity> list = groupUserMapper.queryUsersListPage(param);
		PageData<UserEntity> pd = new PageData<UserEntity>();
		pd.setQueryResult(list);
		pd.setQueryParam(param);
		return pd;
	}
	
	/**
	 * 查询所有用户分页列表（方法重写）
	 * @param param
	 * @return
	 */
	public PageData<GroupUserEntity> queryNoGroupUsersListPage(QueryParam param) {	
		List<GroupUserEntity> list = groupUserMapper.queryNoGroupUsersListPage(param);
		PageData<GroupUserEntity> pd = new PageData<GroupUserEntity>();
		pd.setQueryResult(list);
		pd.setQueryParam(param);
		return pd;
	}
	
	/**
	 * 查询已在该组下的用户分页列表（方法重写）
	 * @param param
	 * @return
	 */
	public List<GroupUserEntity> queryExistGroupUsersListPage(String groupId) {	 
		List<GroupUserEntity> list = groupUserMapper.queryExistGroupUsersList(groupId); 
		return list;
	}
	
}
